package com.dhj.streamTest;

import com.dhj.streamTest.entity.Author;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo2 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();
        Stream<Author> stream = authors.stream();





        Integer[] array = {1,2,3,4,5};

        // 方式一
        Stream<Integer> stream2 = Stream.of(array);
        // 方式二
        Stream<Integer> stream1 = Arrays.stream(array);

        stream1.distinct().forEach(num -> System.out.println(num));





        Map<String,Integer> map = new HashMap<>();
        map.put("蜡笔小新",19);
        map.put("黑子",17);
        map.put("日向翔阳",16);

        Stream<Map.Entry<String, Integer>> stream3 = map.entrySet().stream();

        stream3.distinct().filter(new Predicate<Map.Entry<String, Integer>>() {
            @Override
            public boolean test(Map.Entry<String, Integer> stringIntegerEntry) {
                return stringIntegerEntry.getValue() > 16;
            }
        }).forEach(obj -> System.out.println(obj.getKey() +"="+obj.getValue()));


    }
}
